package com.blb.common.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.IOException;

/**
 * 向前端返回数据的格式
 */
@Data
public class ResponseResult<T> {

    //响应码
    private Long code;

    //文字信息
    private String message;

    //具体数据
    private T data;

    public ResponseResult(Long code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public ResponseResult() {
    }

    public Long getCode() {
        return code;
    }

    public void setCode(Long code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static ResponseResult ok(Object data){
        return new ResponseResult(200L,"ok",data);
    }

    public static ResponseResult error(Long code,String message){
        return new ResponseResult(code,message,null);
    }
}
